<template>
    <div class="container scopClass">
        <h3>检验检测</h3>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="采购检测" name="采购检测">
                <el-row style="margin:20px 0;">
                    <el-col :span="7">
                        <el-input style="border-radius: 0 5px 5px 0;width:300px;" placeholder="请输入关键词"  v-model="searchName1">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch1">搜索</el-button>
                        </el-input>
                    </el-col>
                </el-row>
                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                >
                    <el-table-column prop="productName" sortable label="产品名称"></el-table-column>
                    <el-table-column prop="batch" sortable label="采购批号"></el-table-column>
                    <el-table-column prop="num" sortable label="数量">
                        <template slot-scope="scope">{{scope.row.num}}{{scope.row.units}}</template>
                    </el-table-column>
					<el-table-column prop="createtime" sortable label="采购时间"></el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
								v-if="scope.row.isCheck == 0"
                                @click="handleEdit(scope.$index, scope.row)"
                            >检测</el-button>
                            <el-button
                                type="text"
								v-else
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize1" @current-change="handleCurrentChange1" :total="total1" :current-page.sync="currentPage1" style="margin-top:20px"></el-pagination>
            </el-tab-pane>
            <el-tab-pane label="生产检测" name="生产检测">
                <el-row style="margin:20px 0;">
                    <el-col :span="7">
                        <el-input style="border-radius: 0 5px 5px 0;width:300px;" placeholder="请输入关键词"  v-model="searchName2">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch2">搜索</el-button>
                        </el-input>
                    </el-col>

                </el-row>
                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header">
                   <el-table-column prop="productName" sortable label="产品名称"></el-table-column>
                   <el-table-column prop="batch" sortable label="加工批号"></el-table-column>
                   <el-table-column sortable label="成品数量">
                        <template slot-scope="scope">{{scope.row.totalNumber}}{{scope.row.units}}</template>
                   </el-table-column>
                   <!-- <el-table-column prop="grade" sortable label="品级"></el-table-column> -->
                   <el-table-column prop="createtime" sortable label="加工时间"></el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope" >
                            <el-button
                                type="text"
								v-if="scope.row.isCheck == 0"
                                @click="handleEdit(scope.$index, scope.row)"
                            >检测</el-button>
                            <el-button
                                type="text"
								v-else
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize2" @current-change="handleCurrentChange2" :total="total2" :current-page.sync="currentPage2" style="margin-top:20px"></el-pagination>
            </el-tab-pane>


        </el-tabs>
    </div>
</template>

<script>
import {processDetail_findByList,storageManage_findByList} from "@/request/api";
import { productionManagement_inquire,manage_getProcessDetail,productionManagement_search } from '@/request/produceApi';
    export default {
        // components: {
        //     uploadFile
        // },
        data() {
            return {
                state:1,
                activeName: '采购检测',
                materialType: '中药材',
                searchName1: '',
                searchName2: '',
                tableData: [],
                total1: 0,
                currentPage1:1,
                pagesize1:10,
                total2: 0,
                currentPage2:1,
                pagesize2:10,
                listUrl: '',
                action: '',
                added:true,
                edit:true,
            };
        },
        created(){

        },
        mounted(){
           this.init1();
           this.judgmentAuthority();
        },
        destroyed: function () {
            // this.$store.commit("setStorName","")
        },
        methods: {
            init1() {
                var params = {
                    page:this.currentPage1,
                    productName:this.searchName1
                }
                storageManage_findByList(params).then((res=> {
                    this.tableData = res.rows;
                    this.total1 = res.total;
					for(var i=0;i<this.tableData.length;i++){
						this.tableData[i].num = this.tableData[i].number*this.tableData[i].specs
						var st = this.tableData[i].unit.substr(this.tableData[i].unit.lastIndexOf('/', this.tableData[i].unit.lastIndexOf('/') - 1) + 1);
						var str = st.lastIndexOf("\/")
						this.tableData[i].units = st.substring(0,str)
					}


                }))
            },
            init2() {
                var params = {
                    page:this.currentPage2,
                  searchName:this.searchName2
                }
              manage_getProcessDetail(params).then((res=> {
                    this.tableData = res.rows;
                    this.total2 = res.total;
                }))
            },
            // tabs
            handleClick(tab, event) {
                if (tab.label == '采购检测') {
                    this.init1();
                } else if (tab.label == '生产检测') {
                    this.init2();
                }
            },
            //
            handleEdit(index,row){
                this.$router.push({
                    path: '/scexamination/detection',
                    query: {
                        id: row.id,
                        type:this.activeName
                    }
                });
            },
            // 查看
            handleView(index,row){
                this.$router.push({
                    path: '/scexamination/check',
                    query: {
                        id: row.id,
                        type:row
                    }
                });
            },
            // 删除
            handleDelete(index,row){

            },

            // 列表搜索
            handleSearch1() {
                this.currentPage1 = 1
                this.init1()
            },
            handleSearch2() {
                this.currentPage2 = 1
                this.init2()
            },
            // 分页事件
            handleCurrentChange1(val){
                this.currentPage1 = val
                this.init1()
            },
            handleCurrentChange2(val){
                this.currentPage2 = val
                this.init2()
            },
            //判定操作按钮显示
            judgmentAuthority(){
                var type = JSON.parse(localStorage.getItem("panduanzhuangtai"))
                type.map(item1 => {
                    if(item1.name == '检验检测' && item1.children != null){
                        for(var i = 0; i < item1.children.length; i++){
                        if(item1.children[i].name == '检测') this.added = false;
                        if(item1.children[i].name == '查看') this.edit = false;
                    }
                    }
                })
            }
        }
    }
</script>

<style lang="less" scoped>
// 深度作用器
/deep/.upload-daoru{
    .el-upload{
        border: none;
        width: auto;
        height: auto;
        border-radius: 0;
        float: right;
        margin-right: 10px
    }
}
.el-col{
    margin-bottom: 0;
}
/* .scopClass .el-table{ margin-top: 20px;} */
 .el-pagination{
    text-align: center;
}
/*
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
} */
</style>
